#!/bin/sh

clear
APPLICATION_NAME=zxpisweb

echo =========================================
echo ---------- Install $APPLICATION_NAME ----------
echo =========================================

WEBAPP=/opt/$APPLICATION_NAME

echo "[$(uname -n)] Install path: $WEBAPP"
read -p "Press Enter to start install ..." webapp_start

#=========================================
echo ===== Install check old install
#=========================================

now_date=$(date +%Y%m%d-%H%M%S)

if [ -d "$WEBAPP" ]; then
	echo "WARNING: there has find installed ..."
	read -p "Press [OK] to backup and continue install, otherwise exit..." webapp_continue

	if [ "X$webapp_continue" = "XOK" ]; then 
		echo "Backup old intalled to $WEBAPP-$now_date ..."	
		mv -f $WEBAPP $WEBAPP-$now_date
	else
		echo "Exit install."
		exit
	fi
fi

echo "OK"

#=========================================
echo ===== Install start
#=========================================

echo $(date +%Y-%m-%d_%H:%M:%S)
echo "Tar this package, please waiting about 30 second..."
tar -C /opt -xf $APPLICATION_NAME.tar.gz
echo $(date +%Y-%m-%d_%H:%M:%S)

echo "OK"

#=========================================
echo ===== Set env
#=========================================

cd $WEBAPP
sh ./setenv.sh

cp -rf $WEBAPP/log.properties /root

sh ./showconfig.sh

#=========================================
echo ===== Reboot
#=========================================

read -p "Press Enter to reboot system..." ZXIPI_reboot
reboot
